<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
  <meta name="referrer" content="never">
  <title>offsetParent</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    ul {
      list-style: none;
    }


  </style>
</head>
<body>
  <div class="box">
    <div class="inner">
      <div class="insert"></div>
    </div>
  </div>
  <script type="text/javascript">
    var insert = document.querySelector(".insert");

    console.log("box inner 都没有定位 =>");
    console.log(insert.offsetParent);

    console.log("box 添加定位");
    insert.parentNode.parentNode.style.position = "relative";
    console.log(insert.offsetParent);

    console.log("inner 添加定位");
    insert.parentNode.style.position = "absolute";
    console.log(insert.offsetParent);

    console.log("insert 设置fixed定位");
    insert.style.position = "fixed";
    console.log(insert.offsetParent);

  </script>
</body>
</html>